******************
**** Table B8 ****
****************** 

use "$data/paymentdata_ready" , clear

keep if t==1

gen interventionremainder=interventionsuminvoice-interventionsumpayment
gen postratiomod=postsumpayment/(postsuminvoice+interventionremainder)
winsor postratiomod, gen(postratiomodw1) p(0.01)

sum postratiomodw1 if treatmentall==0, det

log using "$output/table b8", replace

reg postratiomodw1 treatmentidentityd2 treatmentidentityd3 treatmentidentityd4 teamdummy* firststickerdummy* , cluster(dayteam)

reg postratiomodw1 treatmentidentityd2 treatmentidentityd3 treatmentidentityd4 teamdummy* firststickerdummy* preratiow1 lastdebt_demeanedw1 prepaymentsmadedummy* , cluster(dayteam)

capture program drop Ey_boot
program define Ey_boot, eclass
twopm postratiomodw1 treatmentidentityd2 treatmentidentityd3 treatmentidentityd4 ///
firststickerdummy* teamdummy* preratiow1 lastdebt_demeanedw1 prepaymentsmadedummy* /// ///
, firstpart(probit) secondpart(regress) vce(cluster dayteam)
margins, dydx(treatmentidentityd2 treatmentidentityd3 treatmentidentityd4) nose post
end
bootstrap _b, seed(340) reps(1000): Ey_boot

test treatmentidentityd2 = treatmentidentityd3
test treatmentidentityd2 = treatmentidentityd4
test treatmentidentityd3 = treatmentidentityd4

log close
